package com.hwy.struts.interceptor;

import org.apache.struts2.ServletActionContext;

import com.hwy.struts.domain.SysUser;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

// 使用自定义的拦截器，拦截Action的请求
// MethodFilterInterceptor  =>  继承这个父类可以在拦截器配置里面过滤不拦截的方法
public class PrivilegeInterceptor extends MethodFilterInterceptor{

	@Override
	protected String doIntercept(ActionInvocation arg0) throws Exception {
		// 获取session
		SysUser attribute = (SysUser)ServletActionContext.getRequest().getSession().getAttribute("admin_user");
		if(attribute == null) {
			// 没有登录
			ActionSupport aSupport = (ActionSupport)  arg0.getAction();
			aSupport.addActionError("暂未登录");
			return aSupport.LOGIN;
		}else {
			// 已经登录放行
			
			return arg0.invoke();
		}
	}

}
